package GUI;

import processing.core.PApplet;
import Backend.Album;

public class VisualiseAlbum extends PApplet {
	private PApplet parent;
	private Album a;
	private int index;
	private final int gap = 10;
	private final int width = 200;
	private final int height = 30;

	public VisualiseAlbum(PApplet p, Album a, int i) {
		this.a = a;
		this.parent = p;
		this.index = i;
	}

	void display() {
		parent.stroke(0, 0, 0);
		if(over() == 0)
			parent.fill(255, 0, 255);
		else
			parent.fill(0, 255, 0);			
		parent.rect((width * index) + (gap*index)+gap, gap, width, height);
		parent.fill(255, 255, 255);
		parent.text(a.getTitle(), ((index*width)+ (gap*index)+gap)+width/2-parent.textWidth(a.getTitle())/2, gap + 20);
		for (int i = 0; i < a.getSongs().length; i++) {
			if(over()-1 == i)
				parent.fill(255, 0, 0);
			else
				parent.fill(0, a.getSong(i).getPlays(), 0);
			parent.rect((width * index) + (gap*index)+ gap, (height * (i + 1))+gap, width, height);
			parent.fill(255, 255, 255); 
			parent.text(a.getSong(i).getTitle(), ((index*width)+ (gap*index)+gap)+width/2-parent.textWidth(a.getSong(i).getTitle())/2, gap + 20 + (height * i) + height);
		}
	}
	
	int over(){
	    if(parent.mouseX >= (width * index) + (gap*index)+gap && parent.mouseX <= (width * index) + (gap*index)+gap + width){
	    	if(parent.mouseY >= gap && parent.mouseY <= (height * (a.getSongs().length + 1))+gap+1){
	    		System.out.println(parent.random(10));
	    		return ((parent.mouseY-gap)-(parent.mouseY-gap)%height)/height;
	    	}
	    }
	    return -1;
	}
}
